package com.yzt.minemodule.wallet;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.yzt.zhuju.arouter.RouterMine;
import com.yzt.zhuju.base.BaseActivity;
import com.yzt.zhuju.dialog.adapter.DiamondRechargeAdapter;
import com.yzt.zhuju.network.AresSubscriber;
import com.yzt.zhuju.network.biz.BizLayer;
import com.yzt.zhuju.network.entity.goods.RechargeBean;
import com.yzt.zhuju.network.entity.mine.wallet.WalletBean;
import com.yzt.zhuju.utils.recyclerutils.GridItemDecoration;
import com.yzt.zhuju.widget.tuiview.DinTextView;
import com.yzt.minemodule.R;
import com.yzt.p_base.utils.SharedPreferenceUtil;

/**
 * author : bob
 * date   : 2022/11/16
 * desc   : 钻石充值
 */
@Deprecated
@Route(path = RouterMine.ACTIVITY_RECHARGE_DIAMOND)
public class DiamondRechargeActivity extends BaseActivity {

    private DinTextView tvDiamond;

    private DiamondRechargeAdapter diamondRechargeAdapter;

    private String productId;

    @Override
    public int getLayoutId() {
        return R.layout.activity_diamond_recharge;
    }

    @Override
    public void installViews() {

        mTitleBar.setTitle(getString(R.string.recharge_center));

        tvDiamond = findViewById(R.id.diamonds_balance_tv);
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        diamondRechargeAdapter = new DiamondRechargeAdapter();
        recyclerView.setLayoutManager(new GridLayoutManager(mActivity, 3));
        recyclerView.setAdapter(diamondRechargeAdapter);

        recyclerView.addItemDecoration(new GridItemDecoration.Builder()
                .divider(24)
                .build());

        diamondRechargeAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                for (RechargeBean bean : diamondRechargeAdapter.getData()) {
                    bean.setCheck(false);
                }
                productId = diamondRechargeAdapter.getData().get(position).getPackId();
                diamondRechargeAdapter.getData().get(position).setCheck(true);
                diamondRechargeAdapter.notifyDataSetChanged();
            }
        });

        findViewById(R.id.tv_next).setOnClickListener(v -> {

            if (productId == null) {
            }
        });

        loadPageData();
    }

    /**
     * 加载充值列表数据
     */
    private void loadPageData() {

        // 获取钻石余额
        BizLayer.getInstance().getMineModule().wallet( new AresSubscriber<WalletBean>() {
            @Override
            protected void onSuccess(WalletBean walletEntry) {
                // 钻石信息
                tvDiamond.setText(String.valueOf(walletEntry.getCandyNum()));
                SharedPreferenceUtil.getInstance().putValue("limitCache", true);
                SharedPreferenceUtil.getInstance().putValue("limitDiamond",String.valueOf(walletEntry.getCandyNum()));
            }
        });
    }
}
